import MatterManager from '../../managers/MatterManager'

export default class BallMatter extends Laya.Script{
    private matterManage =  MatterManager.instance;
    private container: Laya.Sprite;

    private ball: any;
    private ballX: number = 100;
    private ballY: number = 100;
    private ballRadius: number = 25;

    constructor() {
        super();
    }

    public onAwake(){
        this.container = this.owner as Laya.Sprite;
        this.container.pivot(this.container.width/2, this.container.height/2);

        this.ball = this.matterManage.produceBall(this.ballX, this.ballY, this.ballRadius); 
        // this.ball.collisionFilter = {
        //     group: -1
        // };
        this.ball.parentContainer = this.container;

        this.matterManage.addToWorld(this.ball);
        this.matterManage.setBallVec(this.ball, Math.random()*10-5, Math.random()*10-5);
    }
    
    // 描边-->调试使用  子弹是运动的，换种描边方法
    public drawBulletBorder(drawContainer: Laya.Sprite): void{
        this.matterManage.drawBodyBorder(drawContainer, this.ball.vertices);
    }

    public onUpdate(){
        this.container.x = this.ball.position.x;
        this.container.y = this.ball.position.y;
    }
    
}